package com.example.safeassistan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.safeassistan.R;

public class ExitAnswerProblemDialog1 extends Dialog {
    private TextView tvSurPlus,tvUnEditCount;
    private String surPlusTime="";
    private int totalCount=0;
    private int unEditCount=0;
    private ClickListenerInterface clickListenerInterface;

    public ExitAnswerProblemDialog1(Context context,String surPlusTime,int totalCount,int unEditCount) {
        super(context, R.style.custom_dialog_style);
        this.surPlusTime=surPlusTime;
        this.totalCount=totalCount;
        this.unEditCount=unEditCount;
    }

    public interface ClickListenerInterface {
        void doSubmit();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置不显示键盘
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        setContentView(R.layout.dialog_exit_answer_problem1);
        TextView tvContinue=findViewById(R.id.tvContinue);
        TextView tvExit=findViewById(R.id.tvExit);
        tvSurPlus=findViewById(R.id.tvSurPlus);
        tvSurPlus.setText("剩余时间："+surPlusTime);
        tvUnEditCount=findViewById(R.id.tvUnEditCount);
        tvUnEditCount.setText(unEditCount+"题");
        RingProgressBar ringProgressBar=findViewById(R.id.ringProgressBar);
        ringProgressBar.setBgRing(0xffFFF7F0,10);
        ringProgressBar.setProgressRing(0xffFF9035,10);
        ringProgressBar.setMax(totalCount);
        ringProgressBar.setProgress(unEditCount);
        tvExit.setOnClickListener(new clickListener());
        tvContinue.setOnClickListener(new clickListener());
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
    }


    public void setClicklistener(ClickListenerInterface clickListener) {
        clickListenerInterface = clickListener;
    }

    private class clickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tvContinue:
                    dismiss();
                    break;
                case R.id.tvExit:
                    clickListenerInterface.doSubmit();
                    break;
            }
        }
    }
}
